<template>
  <!-- 登录后的页面 -->
  <div class="users-page">
    <!-- 背景、头像区域 -->
    <div class="users-box">
      <img
        src="http://liufusong.top:8080/img/avatar.png"
        alt=""
        class="users-bg"
      />
      <!-- 资料背景 -->
      <div class="users-info">
        <img
          class="head-img"
          :src="`http://liufusong.top:8080` + userInfoList.avatar"
          alt=""
        />
        <p class="users-name">{{ userInfoList.nickname }}</p>
        <a class="logout" @click="rebackOrLogout">退出</a>
        <p class="set-info">编辑个人资料 ▶</p>
      </div>
      <!-- 6个选项 -->
      <van-grid :column-num="3" :border="false">
        <van-grid-item icon="star-o" to="/collect" text="我的收藏" />
        <van-grid-item icon="wap-home-o" to="/myrent" text="我的出租" />
        <van-grid-item icon="underway-o" text="看房记录" />
        <van-grid-item icon="credit-pay" text="成为房主" />
        <van-grid-item icon="contact" text="个人资料" />
        <van-grid-item icon="service-o" text="联系我们" />
      </van-grid>
      <div class="foot-banner">
        <img src="http://liufusong.top:8080/img/profile/join.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/user'
import { getToken, delToken } from '@/utils/storage'
export default {
  name: 'users-page',
  data () {
    return {
      userInfoList: {}
    }
  },

  async created () {
    if (getToken) {
      const { body } = await getUserInfo()
      // console.log(body)
      this.userInfoList = body
    }
  },
  methods: {
    rebackOrLogout () {
      this.$dialog
        .confirm({
          title: '提示',
          message: '是否确定退出？'
        })
        .then(() => {
          // on confirm
          delToken()
          this.$toast.success('退出成功')
          this.$router.push('/user')
        })
        .catch(() => {
          // on cancel
        })
    }
  }
}
</script>

<style lang="less" scoped>
.users-box {
  position: relative;
}
.users-bg {
  width: 100%;
}
.users-info {
  position: absolute;
  left: 7.5%;
  top: 170px;
  width: 85%;
  height: 205px;
  background-color: #fff;
  box-shadow: 0 0 10px 3px #ddd;
  text-align: center;
}
.head-img {
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 5px solid #f5f5f5;
  box-shadow: 0 0 2px 2px #bdbdbd;
}
.users-name {
  margin-top: -20px;
  margin-bottom: 10px;
}
.logout {
  display: inline-block;
  width: 54px;
  height: 20px;
  background-color: #21b97a;
  font-size: 12px;
  color: #fff;
  border-radius: 30px;
}
.set-info {
  font-size: 12px;
  color: #999;
  margin-top: 20px;
}
.foot-banner {
  position: fixed;
  bottom: 30px;
  text-align: center;
}
.foot-banner img {
  width: 92%;
}
</style>
